#ifndef SOCKET_H
#define SOCKET_H

#include <QTcpSocket>

/**
 * @brief The Socket class overriding a QTcpSocket by providing a necessary layer of abstraction for websocket. A WebSocket is really ready when the handshake has succeded. Then it can begin to
 * receive data. Then the dataReceived() signal sends the effectively received data. For websocket datas are encoded. Therefore by overriding processIncomingData() it is simple to get the decoded datas
 * For the same reason, write has been overriding from QIODevice because a websocket send a header depending on the payload before the payload. By overriding write(), it is possible to send this paticular packet.
 */
class Socket : public QTcpSocket
{
    Q_OBJECT
public:
    /**
     * @brief Socket is a generic constructor
     * @param parent is the parent QObject of the Socket
     */
    Socket(QObject *parent = 0);

    /**
     * @brief write sends 'data' over the network
     * @param data is the data to send
     * @return
     */
    virtual qint64 write(const QByteArray& data);

public Q_SLOTS:
    /**
     * @brief processIncomingData processes the incoming data. This slot is connected to the readyRead() signal
     */
    virtual void processIncomingData();

Q_SIGNALS:
    /**
     * @brief dataReceived is a signal emitted when the socket has received effective data. It stores it in a QByteArray.
     */
    void dataReceived(QByteArray);

private:

};

#endif
